package org.damocode.iot.network.udp;

import lombok.*;
import org.springframework.util.StringUtils;

import java.net.InetSocketAddress;

/**
 * @Description:
 * @Author: zzg
 * @Date: 2022/7/18 11:29
 * @Version: 1.0.0
 */
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UdpSupportProperties {

    private String id;

    private String remoteAddress;

    private int remotePort;

    private String localAddress;

    private int localPort;

    //工作线程数
    private int instance;

    private int receiverPacketSize = 0xffff;

    public InetSocketAddress createRemoteAddress() {
        if (StringUtils.hasText(remoteAddress)) {
            return new InetSocketAddress(remoteAddress, remotePort);
        } else {
            return null;
        }
    }

    public InetSocketAddress createLocalAddress() {
        if (StringUtils.hasText(localAddress)) {
            return new InetSocketAddress(localAddress, localPort);
        } else {
            return new InetSocketAddress(localPort);
        }
    }

}
